import 'dart:async';
import 'dart:convert';

import 'package:flutter/services.dart';
import 'package:mobile_app.core/core/domain/stores/asset_store/store.dart';

class AssetStoreImpl implements AssetStore {
  AssetStoreImpl({
    required String assetStoreContentPath,
  }) : _assetStoreContentPath = assetStoreContentPath;

  final String _assetStoreContentPath;

  late final Map<String, dynamic> _storeContent;

  @override
  Future<void> initialize() async {
    final storeContentString = await rootBundle.loadString(_assetStoreContentPath);
    // _storeContent = await compute(_parseJson, storeContentString);
    _storeContent = _parseJson(storeContentString);
  }

  @override
  Future get({
    required String key,
  }) async {
    return Future.value(_storeContent[key]);
  }
}

Map<String, dynamic> _parseJson(String storeContentString) {
  final Map<String, dynamic> storeContent = jsonDecode(storeContentString);
  return storeContent;
}
